<!--
笔记增加
 add by yyp 2019-05-25
-->
<template lang="pug">
  kalix-dialog.user-add(bizKey="Note" ref="kalixBizDialog" v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL" v-bind:submitBefore="submitBefore")
    div.el-form(slot="dialogFormSlot" style=" width:60%;margin:auto;")
      el-form-item.short(label="用户名" prop="userName" v-bind:label-width="labelWidth" v-bind:rules="rules.userName")
        el-select(v-model="formModel.userId" placeholder="请选择" @change="getUid")
          el-option(v-for="item in options" v-bind:key="item.id" v-bind:label="item.name" v-bind:value="item.id")
      el-form-item.short(label="课程" prop="cname" v-bind:label-width="labelWidth" v-bind:rules="rules.cname")
        el-select(v-model="formModel.cid" placeholder="请选择" @change="getCid")
          el-option(v-for="item in optionss" v-bind:key="item.id" v-bind:label="item.name" v-bind:value="item.id")
      el-form-item(label="笔记标题" prop="noteTitle" label-width="120px" v-bind:rules="rules.noteTitle")
        el-input(v-model="formModel.noteTitle" style="width:80%")
      el-form-item.short(label="笔记附件" prop="noteEnclosure" v-bind:label-width="labelWidth")
        kalix-clansman-upload(:action="action" v-on:filePath="getFilePath" fileType="img"  :fileList="fileList" tipText="只能上传jpg/png文件")
      el-form-item(label="笔记详情" prop="noteContent" label-width="120px" v-bind:rules="rules.noteContent")
        el-input(v-model="formModel.noteContent" style="width:80%"  type="textarea")
</template>

<script type="text/ecmascript-6">
  import FormModel from './model'
  import {NoteURL} from '../../config.toml'
  import KalixClansmanUpload from '../../../../../components/fileUpload/upload'
  import {baseURL} from '../../../../../config/global.toml'
  import KalixSelect from '../../../../../components/corelib/components/common/baseSelect'
  export default {
    name: 'noteAdd',
    components: {KalixSelect, KalixClansmanUpload},
    data() {
      return {
        formModel: Object.assign({}, FormModel),
        action: baseURL + '/camel/rest/upload',
        rules: {
          name: [{required: true, message: '请输入名称', trigger: 'blur'}]
        },
        targetURL: NoteURL + '/addNote',
        filePathArr: [],
        fileList: [],
        labelWidth: '110px',
        options: [],
        optionss: []
      }
    },
    mounted() {
      this.getUname()
      this.getCname()
    },
    methods: {
      getFilePath(filePath, fileName) {
        this.filePathArr.push(filePath)
      },
      submitBefore(baseDialog, callBack) {
        let filePath = ''
        if (this.filePathArr.length > 0) {
          this.filePathArr.forEach(e => {
            filePath += e + ','
          })
          filePath = filePath.substr(0, filePath.length - 1)
        }
        console.log('filePath==========', filePath)
        baseDialog.formModel.noteEnclosure = filePath
        callBack()
      },
      getUname() {
        this.axios.request({
          method: 'GET',
          url: '/camel/rest/users'
        }).then(res => {
          console.log('res========', res.data)
          this.options = res.data.data
        })
      },
      getUid(val) {
        let obj = {}
        obj = this.options.find((item) => {
          return item.id === val
        })
        this.formModel.userName = obj.name
      },
      getCname() {
        this.axios.request({
          method: 'GET',
          url: '/camel/rest/mooc/courses/getAllCourse'
        }).then(res => {
          this.optionss = res.data.data
        })
      },
      getCid(val) {
        let obj = {}
        obj = this.optionss.find((item) => {
          return item.id === val
        })
        this.formModel.cname = obj.name
      },
      proving() {
        this.formModel.liveUrl = this.formModel.liveUrl.replace(/[^\d]/g, '')
        this.formModel.liveUrl = this.formModel.liveUrl.replace('.', '')
      },
      proving1() {
        this.formModel.liveId = this.formModel.liveId.replace(/[^\d]/g, '')
        this.formModel.liveId = this.formModel.liveId.replace('.', '')
      },
      proving2() {
        this.formModel.userId = this.formModel.userId.replace(/[^\d]/g, '')
        this.formModel.userId = this.formModel.userId.replace('.', '')
      }
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">
  .el-form
    width 70%
    margin auto
    .el-input
      width 70%
    .radio
      margin-left 20px
      .el-radio
        color: #3465cb
        font-weight: bold
        font-size: 14px
</style>
